﻿using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;

public enum PropType
{
    None                = 0,
    Power               = 1,//1.力量
    Body                = 2,//2.体质
    Agility             = 3,//3.敏捷
    Natural             = 4,//4.自然
    MAX //最大属性数量
}

[System.Serializable]
public partial class PropSet
{
    [SerializeField] private float[] _props = new float[(int)PropType.MAX];


    /// <summary>
    /// 属性数量
    /// </summary>
    public int Count { get { return (int)PropType.MAX; } }


    /// <summary>
    /// 所有属性信息
    /// </summary>
    public float[] Props { get { return _props; } }


    /// <summary>
    /// 清除数据
    /// </summary>
    public void Clear()
    {
        _props = new float[(int)PropType.MAX];
    }


    /// <summary>
    /// 属性下表是否有效
    /// </summary>
    bool IndexIsValid(int index)
    {
        return index >= 0 || index < (int)PropType.MAX;
    }


    /// <summary>
    /// 属性索引器
    /// </summary>
    public float this[PropType type]
    {
        get { return this[(int)type]; }
        set { this[(int)type] = value; }
    }


    /// <summary>
    /// 属性索引器
    /// </summary>
    public float this[int propIndex]
    {
        get { return IndexIsValid(propIndex) ? _props[propIndex] : 0; }
        set { if (IndexIsValid(propIndex)) { _props[propIndex] = value; } }
    }


    /// <summary>
    /// 某属性增加
    /// </summary>
    public void AddProp(PropType type, float val)
    {
        this[type] += val;
    }


    /// <summary>
    /// 某属性增加
    /// </summary>
    public void AddProp(int propIndex, float val)
    {
        this[propIndex] += val;
    }


    /// <summary>
    /// 克隆
    /// </summary>
    public PropSet Clone()
    {
        PropSet copy = new PropSet();
        copy._props.CopyTo(this._props, 0);
        return copy;
    }


    /// <summary>
    /// 获取指定属性信息
    /// </summary>
    public PropSet GetAttributeData(List<PropType> typeList)
    {
        PropSet propData = new PropSet();

        foreach (var type in typeList)
        {
            propData[type] = this[type];
        }

        return propData;
    }
}
